﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TeamRanking
{
    public class RankingList
    {
        private List<Team> rankListing = new List<Team>();
        public List<Team> RankListing
        {
            get { return rankListing; }
            set { rankListing = value; }
        }

        public int NumberofTeams
        {
            get { return rankListing.Count; }
        }

        public void AddTeam(Team newTeam)
        {
            foreach (Team team in rankListing)
                if (team.Name == newTeam.Name)
                {
                    newTeam.Name += " (alt)";
                }
            if (rankListing.Count < 10)
                rankListing.Add(newTeam);
        }

        public List<Team> RankTeams()
        {
            List<Team> sortedListOfTeams = rankListing
                .OrderByDescending(team => team.Wins)
                .ThenBy(team => team.Losses)
                .ThenByDescending(team => team.Points)
                .ThenBy(team => team.PointsAllowed)
                .ThenByDescending(team => team.OffensiveYards)
                .ThenBy(team => team.DefensiveYards)
                .ToList();
            
            int r = 1;
            foreach (Team tm in sortedListOfTeams )
            {
                tm.Rank = r;
                r++;
            }

            return sortedListOfTeams;
        }
    }
}